<template>
	<view>
		<view class="upperinput">
			<text class="fillwidth" style="margin-left: 30px; font-size: 30px;">添加消费：</text>
			<input class="biginput" v-model="inputvalue" type="number" value="" />
			<view class="dialogbutton">
				<button type="default" v-on:click="makeConsume(1)">其他支出</button>
				<button type="primary" v-on:click="makeConsume(0)" style="margin-left: 10px;">饭钱支出</button>
			</view>
			
		</view>
	</view>
</template>

<script>
	var NC = require("../../../common/common.js");
	
	function failmsg(msg){
		uni.showToast({
			icon:"none",
			image:"../../../static/img/warn.png",
			title:msg
		});
	}
	function successmsg(msg){
		uni.showToast({
			icon:"success",
			title:msg
		});
		setTimeout(()=>{
			uni.switchTab({
				url:"../index/index"
			})
		},1000);
	}
	
	export default {
		data() {
			return {
				inputvalue:""
			}
		},
		onShow() {
			NC.NextCalc.loadState();
		},
		methods: {
			makeConsume:function(type){
				var num = parseFloat(this.inputvalue);
				
				if(isNaN(num) || !isFinite(num)){
					failmsg("输入有误，请输入正确的数字");
				    return;
				}
				if(num>10000000){
					failmsg("数字大小超出精度范围。");
				}
				if(num> NC.NextCalc.getAvailableAmount()){
				    failmsg("数字大小超出本月剩余生活费");
				    return;
				}
				if(type==1){
					NC.NextCalc.addOtherConsume(num,new Date());
				}
				else{
					NC.NextCalc.addConsume(num,new Date());
				}
				successmsg("记录消费成功");
			}
		}
	}
</script>

<style>

	.upperinput{
		width: 100vw;
		height: 60vh;
		display: flex;
		flex-direction: column;
		align-items: center;
		justify-content: center;
	}
	.fillwidth{
		width: 100%;
	}
	.biginput{

		font-size: 50px;
		height: 56px;
		width: calc(100% - 50px);
		text-align: right;
		margin-left: 25px;
		margin-right: 25px;
		border-bottom: solid #00ca0d 1px;
	}
	.dialogbutton{
		display: flex;
		margin-top: 10px;
		margin-left: 25px;
		margin-right: 25px;
		flex-direction: row;
		justify-content: flex-end;
		align-self: flex-end;
	}
</style>
